from typing import List


class Solution:
    def singleNumber(self, nums: List[int]) -> int:
        counts = [0] * 32
        for num in nums:
            for j in range(32):
                counts[j] += num & 1
                num >>= 1
        res, m = 0, 3
        for i in range(32):
            res <<= 1
            res |= counts[31 - i] % m

        #counts[31] % m != 0 说明res 溢出 int最大为2147483648所以要对结果取反
        return res if counts[31] % m == 0 else ~(res ^ 0xffffffff)


if __name__ == '__main__':

    list = [-2,-2,1,1,4,1,4,4,-4,-2]
    s = Solution();
    print(s.singleNumber(list))